package org.linlinjava.litemall.admin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.linlinjava.litemall.admin.beans.annotation.LogAnno;
import org.linlinjava.litemall.admin.beans.annotation.LoginAdminId;
import org.linlinjava.litemall.admin.beans.annotation.LoginAdminShopId;
import org.linlinjava.litemall.admin.dto.AdminLumierePackageDTO;
import org.linlinjava.litemall.admin.service.AdminLumierePackageService;
import org.linlinjava.litemall.admin.vo.packagegoods.AdminLumierePackageGoodsSaveReqVO;
import org.linlinjava.litemall.admin.vo.packagegoods.AdminLumierePackageGoodsVO;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.domain.LumierePackage;
import org.springframework.web.bind.annotation.*;


@Api(tags = "套餐管理API")
@RestController
@RequestMapping("admin/package")
@RequiredArgsConstructor
public class AdminLumierePackageController {

    private final AdminLumierePackageService adminLumierePackageService;

    @ApiOperation(value = "生成下一个套餐编号", notes = "根据数据库中最大编号递增生成唯一商品编号")
    @GetMapping("/generatePackageSn")
    @LogAnno
    public Object generatePackageSn(){
        return adminLumierePackageService.generatePackageSn();
    }

    @ApiOperation("套餐管理-查询套餐列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "limit",value = "数量"),
            @ApiImplicitParam(name = "page",value = "当前页"),
            @ApiImplicitParam(name = "packageName",value = "套餐名称")
    })
    @LogAnno
    @GetMapping("/list")
    public ResponseUtil.Response list(LumierePackage lumierePackage,
                                      @RequestParam("limit")Integer limit,
                                      @RequestParam("page")Integer page,
                                      @LoginAdminShopId Integer loginAdminShopId) {
        return adminLumierePackageService.listLumierePackage(lumierePackage,page, limit,loginAdminShopId);
    }

    @ApiOperation("套餐管理-查询套餐列表详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "id"),
    })
    @LogAnno
    @GetMapping("/details")
    public ResponseUtil.Response details(Integer id) {
        return adminLumierePackageService.details(id);
    }

    @ApiOperation("套餐管理-新增套餐")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "packageName",value = "套餐名称"),
    })
    @LogAnno
    @PostMapping("/add")
    public ResponseUtil.Response add(@RequestBody AdminLumierePackageDTO lumierePackageDTO, @LoginAdminId Integer adminId, @LoginAdminShopId Integer shopId )  {
        return adminLumierePackageService.addLumierePackage(lumierePackageDTO,adminId,shopId);
    }

    @ApiOperation("套餐管理-编辑套餐")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "packageName",value = "套餐名称"),
    })
    @LogAnno
    @PutMapping ("/update")
    public ResponseUtil.Response update(@RequestBody AdminLumierePackageDTO lumierePackageDTO)  {
        return adminLumierePackageService.updateLumierePackage(lumierePackageDTO);
    }

    @ApiOperation("套餐管理-编辑套餐")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "packageName",value = "套餐名称"),
    })
    @LogAnno
    @GetMapping ("/update-onSale")
    public ResponseUtil.Response updateOnSale(@RequestParam("id")Integer id,
                                              @RequestParam("isOnSale")Boolean isOnSale)  {
        return adminLumierePackageService.updateOnSale(id,isOnSale);
    }


    @ApiOperation("套餐管理-删除套餐")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "id"),
    })
    @LogAnno
    @DeleteMapping("/delete")
    public ResponseUtil.Response delete(Integer id)  {
        return adminLumierePackageService.deleteLumierePackage(id);
    }

    @ApiOperation("套餐管理-新增套餐商品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "packageId",value = "套餐id"),
    })
    @LogAnno
    @PostMapping("/addPackageGoods")
    public ResponseUtil.Response addPackageGoods(@RequestBody AdminLumierePackageGoodsSaveReqVO reqVO, @LoginAdminId Integer adminId)  {
        return adminLumierePackageService.addPackageGoodsInfo(reqVO,adminId);
    }

    @ApiOperation("套餐管理-查看套餐商品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "packageId",value = "套餐id"),
    })
    @LogAnno
    @GetMapping("/listPackageGoods")
    public ResponseUtil.Response listPackageGoods(Integer packageId)  {
        return adminLumierePackageService.listPackageGoodsInfo(packageId);
    }

    @ApiOperation("套餐管理-删除套餐商品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "套餐商品id"),
    })
    @LogAnno
    @DeleteMapping("/deletePackageGoods/{id}")
    public ResponseUtil.Response deletePackageGoods(@PathVariable("id") Integer id)  {
        return adminLumierePackageService.deletePackageGoodsInfo(id);
    }



}
